<?php 
session_start(); 
	
	if (!$_SESSION["id_no"])
    {
        Header("Location: index.php");
    }
	else{
		if ($_SESSION['account_type']=='root'){
			$header="secured/header_login";
			$admin="yes";
		}
		elseif($_SESSION['account_type']=='Admin'){ 
			$header="secured/header_login";
			$admin="yes";
		}else{
			$header="header";
			$admin="no";
		}
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Ralimo System Panel</title>
<link rel="stylesheet" href="css/screen.css" type="text/css" media="screen" title="default" />
<link rel="stylesheet" href="css/jquery-ui-1.8.21.custom.css" type="text/css" media="screen" title="default" />
<!--[if IE]>
<link rel="stylesheet" media="all" type="text/css" href="css/pro_dropline_ie.css" />
<![endif]-->

<!--  jquery core -->
<script src="js/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/jquery/jquery-ui-1.8.21.custom.min.js" type="text/javascript"></script>


<!--  checkbox styling script -->
<script src="js/jquery/ui.core.js" type="text/javascript"></script>
<script src="js/jquery/ui.checkbox.js" type="text/javascript"></script>
<script src="js/jquery/jquery.bind.js" type="text/javascript"></script>
<script src="js/jquery/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery/geocoder.js"></script>
<script src="js/jquery/jquery.MultiFile.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery/infowindow.js"></script>
<script type="text/javascript" src="js/jquery/jquery.form.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&libraries=places&key=AIzaSyDe8jbfLwcLgh5ERFqcJUGDM_svl2foezQ&sensor=false"></script>

<script type="text/javascript">
$(function(){
	$('input').checkBox();
	$('#toggle-all').click(function(){
 	$('#toggle-all').toggleClass('toggle-checked');
	$('#mainform input[type=checkbox]').checkBox('toggle');
	return false;
	});
});
</script>  

<![if !IE 7]>

<!--  styled select box script version 1 -->
<script src="js/jquery/jquery.selectbox-0.5.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect').selectbox({ inputClass: "selectbox_styled" });
});
</script>
 

<![endif]>

<!--  styled select box script version 2 --> 
<script src="js/jquery/jquery.selectbox-0.5_style_2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect_form_1').selectbox({ inputClass: "styledselect_form_1" });
	$('.styledselect_form_2').selectbox({ inputClass: "styledselect_form_2" });
});
</script>

<!--  styled select box script version 3 --> 
<script src="js/jquery/jquery.selectbox-0.5_style_2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
	$('.styledselect_pages').selectbox({ inputClass: "styledselect_pages" });
});
</script>

<!--  styled file upload script --> 
<script src="js/jquery/jquery.filestyle.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
  $(function() {
      $("input.file_1").filestyle({ 
          image: "images/forms/choose-file.gif",
          imageheight : 21,
          imagewidth : 78,
          width : 310
      });
  });
</script>

<!-- Custom jquery scripts -->
<script src="js/jquery/custom_jquery.js" type="text/javascript"></script>
 
<!-- Tooltips -->
<script src="js/jquery/jquery.tooltip.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
	$('a.info-tooltip ').tooltip({
		track: true,
		delay: 0,
		fixPNG: true, 
		showURL: false,
		showBody: " - ",
		top: -35,
		left: 5
	});
});
</script> 


<!--  date picker script -->
<link rel="stylesheet" href="css/datePicker.css" type="text/css" />
<script src="js/jquery/date.js" type="text/javascript"></script>
<script src="js/jquery/jquery.datePicker.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
        $(function()
{

// initialise the "Select date" link
$('#date-pick')
	.datePicker(
		// associate the link with a date picker
		{
			createButton:false,
			startDate:'01/01/2005',
			endDate:'31/12/2020'
		}
	).bind(
		// when the link is clicked display the date picker
		'click',
		function()
		{
			updateSelects($(this).dpGetSelected()[0]);
			$(this).dpDisplay();
			return false;
		}
	).bind(
		// when a date is selected update the SELECTs
		'dateSelected',
		function(e, selectedDate, $td, state)
		{
			updateSelects(selectedDate);
		}
	).bind(
		'dpClosed',
		function(e, selected)
		{
			updateSelects(selected[0]);
		}
	);
	
var updateSelects = function (selectedDate)
{
	var selectedDate = new Date(selectedDate);
	$('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
	$('#m option[value=' + (selectedDate.getMonth()+1) + ']').attr('selected', 'selected');
	$('#y option[value=' + (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
}
// listen for when the selects are changed and update the picker
$('#d, #m, #y')
	.bind(
		'change',
		function()
		{
			var d = new Date(
						$('#y').val(),
						$('#m').val()-1,
						$('#d').val()
					);
			$('#date-pick').dpSetSelected(d.asString());
		}
	);

// default the position of the selects to today
var today = new Date();
updateSelects(today.getTime());

// and update the datePicker to reflect it...
$('#d').trigger('change');
});
</script>

<!-- MUST BE THE LAST SCRIPT IN <HEAD></HEAD></HEAD> png fix -->
<script src="js/jquery/jquery.pngFix.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).pngFix( );
});
</script>

<script type="text/javascript">
	$(document).ready(function(){
		$("#vehicle_model_enable").hide();
		$("#vehicle_type_enable").hide();
		$("#vehicle_capacity_enable").hide();
		$("#update_enable").hide();
		$("#change_picture").hide();
		$("#upload_picture").hide();
		$("#enable_invisible_box").hide();
		
		$("#vehicle_type").autocomplete({
			source: "query/getvehicletype.php",
			minLength: 2,
			open: function(){
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			},
			close: function(){
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			}
		
		});
		
		$("#edit_enable").click(function(){
			$("#vehicle_model_enable").show();
			$("#vehicle_model_disabled").hide();
			$("#vehicle_type_enable").show();
			$("#vehicle_type_disable").hide();
			$("#vehicle_capacity_enable").show();
			$("#vehicle_capacity_disable").hide();
			
			$("#update_enable").show();
			$("#change_picture").show();
		});
		
		$("#change_picture").click(function(){
			$("#upload_picture").show();
			$("#change_pic").hide();
			
		});
		
		$("#photoimg").live('change', function(){
			$("#picpreview").html('');
			$("#picpreview").html('<img src="images/shared/loader.gif" alt="Uploading...."/>');
			$("#imageformvehicle").ajaxForm({
				target: '#picpreview'
			}).submit();
			
		});

	});
</script>
</head>
<body> 

<?php 
include("template/$header.php");
$page = (isset($_GET['page']))?$_GET['page']:'home';

	require "query/db_connection.php";

	$id = $_GET['id'];
	$affiliate_id = $_GET['affid'];
	
	$sql1 = "SELECT 
			 vehicles.vehiclemodel,
			 vehicles.image,
			 vehicles.vehicletype,
			 vehicles.capacity
			 FROM 
			 vehicles
			 WHERE vehicleid='$id' ";
	$res = mysql_query($sql1);
	
	$sql2 = "SELECT
			 vehicles.vehiclemodel,
			 vehicles.image,
			 vehicles.vehicletype,
			 vehicles.capacity
			 FROM 
			 vehicles
			 WHERE vehicleid='$id'";	
	$res2 = mysql_query($sql2);				
	$count = mysql_num_rows($res2);
	
	while($row = mysql_fetch_array($res2)){
		$vehiclemodel = $row['vehiclemodel'];
	}
	
	if(isset($_POST['button'])){
		$vehicle_model = $_POST['vehicle_model'];
		$vehicle_type = $_POST['vehicle_type'];
		$capacity = $_POST['capacity'];
		//$photoimg = $_SESSION['varname'];
		
		$sql3="UPDATE
					vehicles AS v, airportrate AS a, hourlyrate AS h
				SET
					v.vehiclemodel='$vehicle_model',
					v.vehicletype='$vehicle_type',
					v.capacity='$capacity',
					a.vehicletype='$vehicle_type',
					a.vehiclemodel='$vehicle_model',
					h.vehicletype = '$vehicle_type',
					h.vehiclemodel = '$vehicle_model'
				WHERE
				v.vehicleid='$id'
				AND 
				a.affiliateid ='$affiliate_id'
				AND
				a.vehiclemodel ='$vehiclemodel'
				AND
				h.vehiclemodel ='$vehiclemodel'
				";
		mysql_query($sql3);
		echo"<script type='text/javascript'>
				window.location.replace('affiliate_vehicles.php?id=".$affiliate_id."');
			 </script>";
	}
	
	if(isset($_POST['button_picture'])){
		$vehicle_id = $_POST['vehicle_id'];
		$photoimg = $_SESSION['varname'];
		$sql4 = "UPDATE
				 vehicles
				 SET
				 image='$photoimg'
				 WHERE
				 vehicleid='$vehicle_id'";
		mysql_query($sql4);
		echo"<script type='text/javascript'>
				window.location.replace('affiliate_vehicles.php?id=".$affiliate_id."');
			 </script>";
	
	}
?>
<!--  start nav-outer-repeat................................................... END -->
<div class="clear"></div>
<!-- start content-outer ........................................................................................................................START -->
<div id="content-outer">
<!-- start content -->		
	<div id="content">

	<!--  start page-heading -->
	<div id="page-heading">
		<h1><?php echo $vehiclemodel;?></h1>
	</div>
	<!-- end page-heading -->
	
	<div id="back_affiliate_vehicles_view" >
		<?php
		 if($_SESSION['account_type'] == 'root'){
			echo"<a id='edit_enable' href='#'><img src='images/forms/edit.png'/></a>
				";
		}elseif($_SESSION['account_type'] == 'Admin'){
			echo"<a id='edit_enable' href='#'><img src='images/forms/edit.png'/></a>
				 ";
		}else
		?>
			<a href="<?php echo "affiliate_vehicles.php?id=".$affiliate_id;?>"><img src="images/forms/back.png" /></a>
	
	</div>
	<table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
	<tr>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
		<th class="topleft"></th>
		<td id="tbl-border-top">&nbsp;</td>
		<th class="topright"></th>
		<th rowspan="3" class="sized"><img src="images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
	</tr>
	<tr>
		<td id="tbl-border-left"></td>
		<td>
		<!--  start content-table-inner ...................................................................... START -->
		<div id="content-table-inner">
			<div id="step-holder">
				<div id="map_canvas"></div>
				<div class="step-dark-left"><a href="">Vehicle Information</a></div>
				<div class="step-dark-round">&nbsp;</div>
				<div class="clear"></div>
			</div>
		
			<!--  start table-content  -->
			<div id="table-content">
				<!--  start product-table ..................................................................................... -->
				<form id="mainform" action="" method="post" >
				<?php
				while($row = mysql_fetch_array($res)){
				echo"<table border='0' cellpadding='0' cellspacing='0'  id='id-form'>
						<tr>
						  <td>Vehicle Model:&nbsp;</td>
						  <td><div id='vehicle_model_disabled'><input type='text' name='vehicle_model' disabled class='inp-form' value='".$row['vehiclemodel']."'  /></div>
								<div id='vehicle_model_enable'>
									<input type='text' name='vehicle_model' id='vehicle_model' class='inp-form'  value='".$row['vehiclemodel']."' />
								</div></td>
						</tr>
						<tr>
							<td>Vehicle Type:&nbsp;</td>
							<td><div id='vehicle_type_disable'><input type='text' name='vehicle_type' disabled class='inp-form' value='".$row['vehicletype']."'/></div>
								<div id='vehicle_type_enable'>
										<input type='text' name='vehicle_type' id='vehicle_type' class='inp-form' value='".$row['vehicletype']."'/>
									</div></td>
						</tr>
						<tr>
							<td>Capacity:&nbsp;</td>
							<td><div id='vehicle_capacity_disable'><input type='text' name='capacity' disabled class='inp-form' value='".$row['capacity']."'/></div>
								<div id='vehicle_capacity_enable'>
									<input type='text' name='capacity' id='capacity' class='inp-form' value='".$row['capacity']."'/>
								</div>
							</td>
						</tr>
					 </table>
					 <div id='change_pic' style='position:absolute; margin-left:320px; margin-top:-120px;'>
						<img alt='".$row['vehiclemodel']."' src='".$row['image']."'>
						<br />
						<a id='change_picture' href='#'><img src='images/forms/change_picture.png' /></a>	
					 </div>
					";
					
				  }
				 ?>
					<div id="update_enable"><input id="button" name="button" type="submit" class="form_update" /></div>
				<!--  end product-table................................... --> 
				</form>
				 <form id="imageformvehicle" method="post" enctype="multipart/form-data" action="query/ajaximage.php">	
					<div id="upload_picture" style="position:absolute; margin-left:320px; margin-top:-120px;">
							<input type="hidden" name="img_type" value="vehicle"/>
							<p>Upload image:<input type="file" name="photoimg" id="photoimg" /></p>
							<div id="picpreview">image shown here.... </div>
							<div id="update_enable_picture"><input id="button_picture" name="button_picture" type="submit" class="form_update" /></div>
					</div>
				</form>
			</div>
				<input type="hidden" name="vehicle_id" value="<?php echo $id;?>" />
			<!--  end content-table  -->	
			<div class="clear"></div>
		</div>
		<!--  end content-table-inner ............................................END  -->
		</td>
		<td id="tbl-border-right"></td>
	</tr>
	<tr>
		<th class="sized bottomleft"></th>
		<td id="tbl-border-bottom">&nbsp;</td>
		<th class="sized bottomright"></th>
	</tr>
	</table>
	<div class="clear">&nbsp;</div>
	

<!--  end content -->
<div class="clear">&nbsp;</div>
</div>
<!--  end content-outer........................................................END -->

<div class="clear">&nbsp;</div>
    
<?php include"template/footer.php"; ?>
 
</body>
</html>